package restless.core.gameObjs {

	import restless.core.interfaces.IColisionable;
	import restless.core.interfaces.ILevel;
	import restless.core.interfaces.IPowerup;
	import restless.core.managers.RLEPowerupManager;
	
	/**
	 * 
	 * @author Jordan Laine
	 * 
	 */
	
	public class RLEGameObj extends RLEBlitMC implements IColisionable, IPowerup {
		private var _speed:Number;
		
		private var parentObject:RLEGameObj;
		private var _level:ILevel;
		
		private var bColide:Boolean = false;
		private var _colisionID:int;
		private var vColisionIds:Vector.<String>;
		
		protected var stageW:Number;
		protected var stageH:Number;
		protected var worldW:Number;
		protected var worldH:Number;
		
		protected var vPowerupBool:Vector.<Boolean> = new Vector.<Boolean>;
		protected var vPowerupIds:Vector.<String> = new Vector.<String>;
		protected var vPowerupFunctions:Vector.<Function> = new Vector.<Function>;
		
		public function powerup(id:String):void {
			var num:int = vPowerupIds.indexOf(id);
			if (num > -1) {
				vPowerupBool[num] = true;
				vPowerupFunctions[num]();
				
			}
		}
		
		public function deactivateAllPowerups():void {
			
		}
		
		public function deactivatePowerup(id:String):void {
			var num:int = vPowerupIds.indexOf(id);
			if (num > -1) {
				vPowerupBool[num] = false;
				vPowerupFunctions[num]();
			}
		}
		
		public function addPowerup(id:String, fun:Function):void {
			var num:int = vPowerupIds.indexOf(id);
			if (num > -1) { return; }
			
			vPowerupIds.push(id);
			vPowerupFunctions.push(fun);
			vPowerupBool.push(false);
		}
		
		public function updateLevelBounds():void {
			stageW = RE.displayWidth;
			stageH = RE.displayHeight;
			worldW = RE.worldWidth;
			worldH = RE.worldHeight;
		}
		
		override public function setRE():void {
			super.setRE();
			updateLevelBounds();
		}
		
		public function set parent(obj:RLEGameObj):void {
			parentObject = obj;
		}
		
		public function get parent():RLEGameObj {
			return parentObject;
		}
		
		public function get speed():Number {
			return _speed;
		}
		
		public function set speed(num:Number):void {
			_speed = num;
		}
		
		public function reset():void {
			
		}
		
		public function set level(level:ILevel):void {
			_level = level;
		}
		
		public function get level():ILevel {
			return _level;
		}
		
		public function colision(bool:Boolean, colision:String = "default"):void {
			bColide = bool;
			tempString = colision;
			
			if (vColisionIds == null) {
				vColisionIds = new Vector.<String>;
			}
			
			var num:int = vColisionIds.indexOf(tempString);
			if (num < 0) {
				if (bColide) {
					vColisionIds.push(tempString);
					colM.addColItem(this, tempString);
				}
			} else {
				if (!bColide) {
					vColisionIds.splice(num, 1);
					colM.removeColItem(this, tempString);
				}
			}
		}
		
		public function collide(obj:IColisionable):Boolean {
			return false;
		}
		
		public function get colisionId():int {
			return _colisionID;
		}
		
		public function set colisionId(num:int):void {
			_colisionID = num;
		}
		
		override public function dispose():void {
			colision(false);
			_level = null;
			vPowerupBool = null;
			vPowerupIds = null;
			vPowerupFunctions = null;
			parentObject = null;
			super.dispose();
		}
		
	}

}